home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 09, No. 06 (1988-06)(MicroSPARC)(Side A).zip / Nibble Volume 09, No. 06 (1988-06)(MicroSPARC)(Side A).po / PRINTER.DUMP.S < prev    next >
Text File  |  1996-12-24  |  8KB  |  259 lines

  1. * Printer Dump
  2. * by Robert Heath
  3. * Copyright(c) 1988
  4. * MicroSPARC, Inc. 1988
  5. * Concord, MA 01742
  6. *
  7. *  This program will add an external command to
  8. *  the ProDOS Basic Interpreter.  This program
  9. *  is a 40/80 column screen dump.  By entering
  10. *  'DUMP', whatever is on the screen will be
  11. *  printed on your printer.
  12.                          ;
  13.                          ;  Assembler: Apple ProDOS Editor-Assembler
  14. ***
  15. *  Program Equates
  16. ***
  17.                          ;
  18.           ORG $8000 
  19. CH        EQU $24        ;Horz. cursor position
  20. CV        EQU $25        ;Vertical cursor position
  21. BASL      EQU $28        ;Address of start of line
  22. CSWL      EQU $36        ;Output hook
  23. CSWH      EQU $37
  24. KSWL      EQU $38        ;Input hook
  25. KSWH      EQU $39
  26. LINE      EQU $3C        ;Variable for line number
  27. A1L       EQU $3C        ;Temp monitor variable
  28. A1H       EQU $3D
  29. A2L       EQU $3E
  30. A2H       EQU $3F
  31. EXTERNCMD EQU $BE07      ;External command handler
  32. VPATH1    EQU $BE6C      ;Pointer to command line
  33. BIENTRY   EQU $BE00      ;Entry point to BI
  34. XTERNADDR EQU $BE50      ;Start of external program
  35. XLEN      EQU $BE52      ;Length of command
  36. XCNUM     EQU $BE53      ;Number of command
  37. PBITS     EQU $BE54      ;Parameters permitted
  38. GETBUFR   EQU $BEF5      ;Allocate buffers
  39. MACHID    EQU $BF98      ;Machine identification
  40. KEYBOARD  EQU $C000      ;Keyboard port
  41. KBDSTROBE EQU $C010      ;Keyboard strobe
  42. RD80VID   EQU $C01F      ;Test if in 80 column mode
  43. *                             ;   High bit set = 80 col
  44. TXTPAGE1  EQU $C054      ;Access text page 1
  45. TXTPAGE2  EQU $C055      ;Access text page 2
  46. VTABZ     EQU $FC24      ;Set BASL to correct line
  47. HOME      EQU $FC58      ;Clear the screen
  48. COUT      EQU $FDED      ;Standard output routine
  49.                          ;
  50. ***
  51. *  Segement I
  52. *  Initialization
  53. *  This section installs the command
  54. *  in the BI and copies the next two
  55. *  sections to a free buffer.
  56. ***
  57.                          ;
  58.           LDA #$01       ;Allocate 1 page
  59.           JSR GETBUFR
  60.           BCS ERROR
  61.           STA A2H        ;Save MSB for copy
  62.           STA XADDRH+1   ;Put MSB in section II
  63.           STA COMPARE+4  ;Save MSB in section II
  64.           LDA EXTERNCMD  ;Save the current pointer
  65.           STA INVALID+2  ; in section II to link the
  66.           LDA EXTERNCMD+1 ; external commands
  67.           STA INVALID+3
  68.           LDA A2H        ;Install our command
  69.           STA EXTERNCMD+1
  70.           LDA #$00
  71.           STA EXTERNCMD
  72.           STA A2L        ;Set LSB for copy
  73.           LDA #<START    ;Get the start of program
  74.           STA A1H        ;  and save for copy
  75.           LDA #>START
  76.           STA A1L
  77.           LDY #$00  
  78. COPY      LDA (A1L),Y    ;Get a byte of the program
  79.           STA (A2L),Y    ; and put it in the buffer
  80.           INY
  81.           BNE COPY       ;Loop until we are done
  82. QUIT.X    RTS
  83.                          ;
  84. ***
  85. *  Error Routine 
  86. ***
  87.                          ;
  88. ERROR     LDX #$00       ;Print the error message
  89. ERROR.1   LDA TXT.ERROR,X
  90.           BEQ ERROR.X
  91.           JSR COUT
  92.           INX
  93.           BNE ERROR.1
  94. ERROR.X   PLA            ;Cancel return
  95.           PLA
  96.           JMP BIENTRY    ;Enter the BI
  97.                          ;
  98.           MSB ON
  99. TXT.ERROR DFB $8D,$8D,$87
  100.           ASC 'NO ROOM FOR THIS COMMAND.'
  101.           DFB $8D,$8D,$00
  102.                          ;
  103.                          ;
  104.           DS $8200-*     ;Install padding
  105.                          ;
  106. ***
  107. *  Main Program
  108. *  This segement is installed in the
  109. *  buffer obtain by FREEBUFF.
  110. *  Note:  This segement must be page alligned
  111. ***
  112.                          ;
  113.           DO >*
  114.           FAIL 1,Main segement not page alligned.
  115.           FIN
  116.                          ;
  117. ***
  118. *  Segement II
  119. *  Command Handler
  120. *  This section determines is 'DUMP'
  121. *  was entered.  If it was, then it
  122. *  tells the BI to execute segement III.
  123. *  Otherwise, it jumps to the next 
  124. *  command handler.
  125. ***
  126.                          ;
  127. START     CLD            ;Identify this as a command
  128.           LDA VPATH1     ;Point to the command
  129.           STA A1L
  130.           LDA VPATH1+1
  131.           STA A1H
  132.           LDY #$04
  133. COMPARE   LDA (A1L),Y
  134.           CMP TXT.DUMP-1,Y
  135.           BNE INVALID
  136.           DEY
  137.           BNE COMPARE
  138.           LDA #$00       ;No parameters needed
  139.           STA PBITS
  140.           STA PBITS+1
  141.           STA XCNUM      ;This is an external command 
  142.           LDA #$03       ;Length of command - 1
  143.           STA XLEN  
  144.           LDA #>MAIN     ;Point to segement III
  145.           STA XTERNADDR
  146. XADDRH    LDA #$00       ;00 changed by segement I
  147.           STA XTERNADDR+1
  148.           CLC
  149.           RTS
  150. INVALID   SEC            ;It's not us, pass to the
  151.           JMP $0000      ;   next command handler
  152.                          ;
  153. ***
  154. *  Segement III
  155. *  Dump Routine
  156. *  This section does the printing
  157. *  of the screen
  158. ***
  159.                          ;
  160. MAIN      EQU *
  161.           LDA CSWL       ;Save the important values
  162.           PHA
  163.           LDA CSWH
  164.           PHA
  165.           LDA KSWL
  166.           PHA
  167.           LDA KSWH
  168.           PHA
  169.           LDA CH
  170.           PHA
  171.           LDA CV
  172.           PHA
  173.           LDX #$FF       ;Initialize 80 col flag
  174.           LDA MACHID     ;Check to see if a 80 col
  175.           AND #$02       ;   card is installed
  176.           BEQ MAIN40     ;No,must be in 40 col mode
  177.           BIT RD80VID    ;In 80 col mode?
  178.           BPL MAIN40     ;No, in 40 col mode
  179.           LDX #$00       ;Yes,set flag for 80 col
  180. MAIN40    EQU *
  181.           TXA            ;Transfer flag to stack
  182.           PHA            ; 0=80 Col   $FF=40 Col
  183.           FIN
  184.           LDA #PRINTER   ;Set output hook 2 printer
  185.           STA CSWH
  186.           LDA #$00
  187.           STA CSWL
  188.           TAX            ;Print the init. string
  189. INIT      LDA STRING,X   ;Get a character
  190.           BEQ INITX      ;Exit if zero
  191.           JSR COUT       ;Print the character
  192.           INX
  193.           BNE INIT       ;Always branch
  194. INITX     LDA #$FF
  195.           STA LINE
  196. PRLINE    INC LINE       ;Move to the next line
  197.           LDA LINE
  198.           STA CV 
  199.           JSR VTABZ      ;Set BASL to point to line
  200.           LDY #$00       ;Initialize to column 1
  201. LOOP      LDA KEYBOARD   ;See if ESC was pressed
  202.           CMP #$9B
  203.           BEQ EXIT       ;Yes, stop printing here
  204.           PLA            ;In 40 col mode?
  205.           PHA   
  206.           BNE COL40      ;Yes, forget page 2
  207.           PHP            ;Save interrupt status
  208.           SEI            ;Turn off the interrupts
  209.           STA TXTPAGE2   ;Access text page 2
  210.           LDA (BASL),Y   ;Get a char from page 2
  211.           STA TXTPAGE1   ;Access text page 1
  212.           PLP            ;Restore interrupt status
  213.           JSR COUT       ;Print the character
  214. COL40     LDA (BASL),Y   ;Get a char from page 1
  215.           JSR COUT       ;  and print it.
  216.           INY            ;Go to the next column
  217.           CPY #$28       ;End of line?
  218.           BNE LOOP       ;No, continue with line
  219.           LDA #$8D       ;Yes, Print a RETURN
  220.           JSR COUT
  221. *         LDA   #$0A
  222. *         JSR   COUT
  223.           NOP            ;Leave room for code that
  224.           NOP            ;  can print a line feed
  225.           NOP 
  226.           NOP
  227.           NOP
  228.           LDA LINE  
  229.           CMP #$17       ;End of the screen?
  230.           BNE PRLINE     ;No, do the next line
  231. EXIT      PLA            ;Clear flag from stack
  232.           PLA
  233.           STA CV
  234.           JSR VTABZ
  235.           PLA
  236.           STA CH
  237.           PLA
  238.           STA KSWH
  239.           PLA
  240.           STA KSWL
  241.           PLA
  242.           STA CSWH
  243.           PLA
  244.           STA CSWL
  245.           STA KBDSTROBE  ;Clear the strobe
  246.           RTS            ;We're done,let's exit
  247.                          ;
  248. ***
  249. *  PROGRAM VARIABLES
  250. ***
  251.                          ;
  252.           MSB ON
  253. STRING    DFB $8D,$8D,$89 ;Set line size to 81 col.
  254.           ASC '82N'      ; and print blank lines
  255.           DFB $8D,$8D,$00 ;80 columns + C.R. + L.F.
  256. PRINTER   EQU $C1        ;MSB of printer addr.
  257.           MSB OFF
  258. TXT.DUMP  ASC 'DUMP'
  259.